package com.ldw.hello.dubbo.service.user.consumer.controller;

import com.ldw.hello.dubbo.service.user.api.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title: UserController</p>
 * <p>Description: </p>
 *
 * @author: dwLiu
 * @date: 2020/3/5 22:07
 */
@RestController
public class UserController {

    @Reference(version = "${user.service.version}")
    private UserService userService;

    @HystrixCommand(fallbackMethod = "hiError")
    @GetMapping(value = "/hi/{name}")
    public String sayHello(@PathVariable(value = "name") String name){
        return userService.sayHello(name);
    }

    public String hiError(String name){
        return "Hystrix fallback :"+ name;
    }
}
